﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ClassBuilder.Comment
{
    /// <summary>
    /// 列表型注释
    /// </summary>
    public class ListItems
    {
        /// <summary>
        /// 列表型注释
        /// </summary>
        /// <param name="items">每一项</param>
        public ListItems(params string[] items)
           : this(ItemType.bullet, items)
        {
            
        }

        /// <summary>
        /// 列表型注释
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="items">每一项</param>
        public ListItems(ItemType type, params string[] items)
        {
            this.Type = type;
            this.Items = new List<string>(items);
        }

        public override string ToString()
        {
            if (Items != null && Items.Count > 0)
            {
                StringPlus plus = new StringPlus();
                plus.AppendLine($"/// <list type=\"{Type.ToString()}\">");
                foreach (var item in Items)
                {
                    plus.AppendLine($"/// <item><description>{item.HtmlHandle()}</description></item>");
                }
                plus.AppendLine("/// </list>");
                return plus.ToString().Trim();
            }
            return string.Empty;
        }

        /// <summary>
        /// 所有行注释
        /// </summary>
        public string[] Lines
        {
            get
            {
                return this.Value?.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            }
        }

        /// <summary>
        /// 根据tab处理tab间隔
        /// </summary>
        /// <param name="tab_space">tab间隔个数</param>
        /// <returns></returns>
        public string ByTabs(int tab_space)
        {
            StringPlus plus = new StringPlus();
            foreach (var line in Lines)
            {
                plus.AppendSpaceLine(tab_space, line);
            }
            return plus.ToString();
        }



        /// <summary>
        /// 项样式
        /// </summary>
        public ItemType Type { get; set; }

        /// <summary>
        /// 项内容
        /// </summary>
        public List<string> Items { get; set; } = new List<string>();


        /// <summary>
        /// 最终显示内容
        /// </summary>
        public string Value
        {
            get
            {
                return this.ToString();
            }
        }
    }
}
